package com.floreantpos.model;

import java.util.Calendar;

import org.apache.commons.logging.LogFactory;

import com.floreantpos.main.Application;
import com.floreantpos.model.base.BaseMember;
import com.floreantpos.model.dao.MemberDAO;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Member extends BaseMember {
	private static final long serialVersionUID = 1L;

	/*[CONSTRUCTOR MARKER BEGIN]*/
	public Member () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
        public int getMemberRefExpired()
        {
            if (this.getRecEXP() != null)
                
                return this.getRecEXP().compareTo(new Date());
            else
                return -1;
        }
        public String getMemberRefDate()
        {
           
            SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
            return dateFormat.format(this.getRecEXP());
        }
	public Member (java.lang.Integer autoId) {
		super(autoId);
	}

	/**
	 * Constructor for required fields
	 */
	
	/*[CONSTRUCTOR MARKER END]*/

//	public final static String USER_TYPE_MANAGER = "MANAGER";
//	public final static String USER_TYPE_CASHIER = "CASHIER";
//	public final static String USER_TYPE_SERVER = "SERVER";

	
	public void doClockIn(Calendar currentTime) {
		setClockedIn(true);
		setLastClockInTime(currentTime.getTime());
		
		//LogFactory.getLog(Application.class).info("terminal id befor saving clockIn=" + terminal.getId());
		
//		AttendenceHistory attendenceHistory = new AttendenceHistory();
//		attendenceHistory.setClockInTime(currentTime.getTime());
//		attendenceHistory.setClockInHour(Short.valueOf((short) currentTime.get(Calendar.HOUR)));
//		attendenceHistory.setUser(this);
//		attendenceHistory.setTerminal(terminal);
//		attendenceHistory.setShift(shift);
		
		MemberDAO.getInstance().saveClockIn(this,currentTime);
	}
	
	public void doClockOut(Calendar currentTime) {
		setClockedIn(false);
		//setLastClockInTime(null);
		
//		attendenceHistory.setClockedOut(true);
//		attendenceHistory.setClockOutTime(currentTime.getTime());
//		attendenceHistory.setClockOutHour(Short.valueOf((short) currentTime.get(Calendar.HOUR)));
		
		MemberDAO.getInstance().saveClockOut(this, currentTime);
	}

	@Override
	public String toString() {
		return " " + getLname();
	}
	
//	public boolean isManager() {
//		return USER_TYPE_MANAGER.equals(getUserType());
//	}
//	
//	public boolean isCashier() {
//		return USER_TYPE_CASHIER.equals(getUserType());
//	}
//	
//	public boolean isServer() {
//		return USER_TYPE_SERVER.equals(getUserType());
//	}
}